package TimeForJAVA8;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * Created with IntelliJ IDEA.
 * 类名：MainTest
 * 开发人员: CoderJu
 * 创建时间: 2019/3/9 22:11
 * 描述:
 * 版本：V1.0
 */
public class MainTest {
    public static void main(String[] args) {
        //getcurrentDate();
        //getcurrentTime();
        //getcurrentYMD();
        //getSpecialDate();
       // compareDate();
       // checkDate();
        //someHoursLater();
        //sonWeekDate();
        //colockTest();
        //compareDate_1();
        //timeTransfer();
        //testDayOfMonth();
       // isLeapYear();
        //diffDate();
        //timeInstant();
        //formateDate();
        ExplainDate();
    }

    private static void ExplainDate() {
        String str = "01 04 2018";
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM dd yyyy");
        LocalDate localDate = LocalDate.parse(str,dateTimeFormatter);
        System.out.println(">>>>"+localDate);
    }

    private static void formateDate() {
        String dateStr = "20190101";
        LocalDate formateDate = LocalDate.parse(dateStr, DateTimeFormatter.BASIC_ISO_DATE);
        System.out.println("格式化后的日期："+formateDate);
    }

    private static void timeInstant() {
        Instant instant = Instant.now();
        System.out.println("现在的时间戳为："+instant);
    }

    private static void diffDate() {
        LocalDate date = LocalDate.of(2019,01,01);
        LocalDate date1 = LocalDate.now();
        Period period = Period.between(date,date1);
        System.out.println(date+"和"+date1+"相差天数为:"+period.getDays());
        System.out.println(date+"和"+date1+"相差月数为:"+period.getMonths());
        System.out.println(date+"和"+date1+"相差年数为:"+period.getYears());
    }

    private static void isLeapYear() {
        LocalDate now = LocalDate.now();
        if(now.isLeapYear()){
            System.out.println("今年是闰年>>>>");
        }else{
            System.out.println("今年不是闰年>>>>");
        }
    }

    private static void testDayOfMonth() {
        LocalDate now = LocalDate.now();
        YearMonth yearMonth = YearMonth.of(now.getYear(),now.getMonthValue());
        int day = yearMonth.lengthOfMonth();
        System.out.println("这个月有："+day+"天");
    }

    private static void timeTransfer() {
        LocalDateTime now = LocalDateTime.now();
        System.out.println("现在："+now);
        ZoneId zoneId = ZoneId.of(ZoneId.SHORT_IDS.get("BET"));
        ZonedDateTime zonedDateTime = ZonedDateTime.of(now,zoneId);
        System.out.println("特定时区时间："+zonedDateTime);

    }

    private static void compareDate_1() {
        LocalDate now = LocalDate.now();
        System.out.println("现在："+now);
        LocalDate date = LocalDate.of(2018,03,01);
        boolean b = now.isAfter(date);
        boolean b1 = now.isBefore(date);
        System.out.println("当前日期在2019-03-01之后："+b+"||之前："+b1);
    }

    private static void colockTest() {
        Clock clock = Clock.systemDefaultZone();
        System.out.println(">>>>>"+clock);
        clock = Clock.systemUTC();
        System.out.println(">>>>>"+clock);
    }

    private static void sonWeekDate() {
        LocalDate now = LocalDate.now();
        System.out.println("现在："+now);
        LocalDate oneWeekAfter = now.plusWeeks(1);
        System.out.println("一周后："+oneWeekAfter);
        oneWeekAfter = now.plusMonths(2);
        System.out.println("二月后："+oneWeekAfter);
        oneWeekAfter = now.plusYears(1);
        System.out.println("一年后："+oneWeekAfter);
    }

    private static void someHoursLater() {
        LocalTime now = LocalTime.now();
        System.out.println("现在："+now);
        LocalTime oneHoursLater =  now.plusHours(3);
        System.out.println("一小时后："+oneHoursLater);
        oneHoursLater = now.plusHours(-10);
        System.out.println("十小时前："+oneHoursLater);
    }

    private static void checkDate() {
        LocalDate birthday = LocalDate.of(1992,3,9);
        MonthDay birthdayMD = MonthDay.of(birthday.getMonthValue(),birthday.getDayOfMonth());
        LocalDate now = LocalDate.now();
        MonthDay nowMD = MonthDay.of(now.getMonthValue(),now.getDayOfMonth());
        if (birthdayMD.equals(nowMD)){
            System.out.println("HAPPY BIRTHDAY");
        }else{
            System.out.println("=====不输出任何信息");
        }
    }

    private static void compareDate() {
        LocalDate localDate = LocalDate.of(2019,8,11);
        LocalDate now = LocalDate.now();
        System.out.println("比较日期："+localDate.equals(now));
    }

    private static void getSpecialDate() {
        LocalDate localDate = LocalDate.of(2019,8,11);
        System.out.println("获取特定日期："+localDate);
    }

    private static void getcurrentYMD() {
        LocalDate localDate = LocalDate.now();
        int Y = localDate.getYear();
        int M = localDate.getMonthValue();
        int D = localDate.getDayOfMonth();
        System.out.println("年："+Y+"||月："+M+"||日："+D);
    }

    public static void getcurrentTime() {
        LocalTime localTime = LocalTime.now();
        System.out.println("当前时间是："+localTime);
    }

    public static void getcurrentDate(){
        LocalDate localDate = LocalDate.now();
        System.out.println("当前日期是："+localDate);
    }
}
